package com.sandking.db.dao;

import com.sandking.db.bean.Zb;
import javax.sql.DataSource;
import org.apache.commons.dbutils.handlers.MapHandler;
import org.apache.commons.dbutils.QueryRunner;
import com.sandking.config.SK_Config;
import java.sql.Connection;
import com.sandking.metadata.jdbc.SK_Query;
import java.util.Map;
import java.util.List;
import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.dbutils.handlers.MapListHandler;

public class ZbDao {
	public static Zb insert(Zb zb){
		Connection conn = SK_Config.getConnection();
		return insert(zb,conn);
	}
	
	public static Zb insert(Zb zb,Connection conn){
		return insert(zb,conn,Zb.TABLENAME);
	}
	
	public static Zb insert(Zb zb,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return insert(zb,conn);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static Zb insert(Zb zb,String tableName){
		Connection conn = SK_Config.getConnection();
		return insert(zb,conn,tableName);
	}
	
	public static Zb insert(Zb zb,Connection conn,String tableName){
		
		SK_Query sq = new SK_Query();
		String sql = "INSERT INTO " +tableName+ " (id,tempid,攻击人id,目标人id,目标用户名称,创建时间,是否可反击,json,星数,是否结算,金币,水,开始战斗时间) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)";
		try {
			int i = (int)sq.insert(conn,sql,zb.getId(),zb.getTempid(),zb.getGjrid(),zb.getMbrid(),zb.getMbyhmc(),zb.getCjsj(),zb.getSfkfj(),zb.getJson(),zb.getXs(),zb.getSfjs(),zb.getJb(),zb.getS(),zb.getKszdsj());
			if(zb.getId()==0){
				zb.setId(i);
			}
			return i > 0 ? zb : null;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		} finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return null;
			}
		}
	}
	
	public static Zb insert(Zb zb,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return insert(zb,conn,tableName);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}		
	}
	
	public static int[] insertBatch(List<Zb> zbs){
		Connection conn = SK_Config.getConnection();
		return insertBatch(zbs,conn);
	}
	
	public static int[] insertBatch(List<Zb> zbs,Connection conn){
		return insertBatch(zbs,conn,Zb.TABLENAME);
	}
	
	public static int[] insertBatch(List<Zb> zbs,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return insertBatch(zbs,conn);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static int[] insertBatch(List<Zb> zbs,String tableName){
		Connection conn = SK_Config.getConnection();
		return insertBatch(zbs,conn,tableName);
	}
	
	public static int[] insertBatch(List<Zb> zbs,Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		String sql = "INSERT INTO " +tableName+ " (id,tempid,攻击人id,目标人id,目标用户名称,创建时间,是否可反击,json,星数,是否结算,金币,水,开始战斗时间) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)";
		try {
			int columnSize = 13;
			int size = zbs.size();
			Object[][] params = new Object[size][columnSize];
			for (int i = 0; i < size; i++) {
				params[i][0] =zbs.get(i).getId();
				params[i][1] =zbs.get(i).getTempid();
				params[i][2] =zbs.get(i).getGjrid();
				params[i][3] =zbs.get(i).getMbrid();
				params[i][4] =zbs.get(i).getMbyhmc();
				params[i][5] =zbs.get(i).getCjsj();
				params[i][6] =zbs.get(i).getSfkfj();
				params[i][7] =zbs.get(i).getJson();
				params[i][8] =zbs.get(i).getXs();
				params[i][9] =zbs.get(i).getSfjs();
				params[i][10] =zbs.get(i).getJb();
				params[i][11] =zbs.get(i).getS();
				params[i][12] =zbs.get(i).getKszdsj();
			}
			int[] is = run.batch(conn,sql,params);
			return is.length > 1 ? is : new int[]{};
		} catch (Exception e) {
			e.printStackTrace();
			return new int[]{};
		} finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return null;
			}
		}
	}
	
	public static int[] insertBatch(List<Zb> zbs,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return insertBatch(zbs,conn,tableName);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}		
	}
	
	public static Zb update(Zb zb){
		Connection conn = SK_Config.getConnection();
		return update(zb,conn);
	}
	
	public static Zb update(Zb zb,Connection conn){
		return update(zb,conn,Zb.TABLENAME);
	}
	
	public static Zb update(Zb zb,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return update(zb,conn);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static Zb update(Zb zb,String tableName){
		Connection conn = SK_Config.getConnection();
		return update(zb,conn,tableName);
	}
	
	public static Zb update(Zb zb,Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		StringBuffer sb = new StringBuffer();
		Map<String, Object> updateColumns = zb.getUpdateColumns();
		int columnSize = updateColumns.size();
		if (updateColumns.isEmpty()) {
			return zb;
		}
		sb.append("UPDATE ");
		sb.append(tableName);
		sb.append(" SET ");
		Object[] values = new Object[(columnSize + 1)];
		int i = 0;
		for (Map.Entry<String, Object> updateColumn : updateColumns.entrySet()) {
			String key = updateColumn.getKey();
			values[i] = updateColumn.getValue();
			i++;
			sb.append(key);
			sb.append("=");
			sb.append("?");
			if (i < columnSize) {
				sb.append(",");
			}
		}
		sb.append(" WHERE ");
		sb.append("id");
		sb.append(" = ?");
		values[columnSize] = zb.getId();
		String sql = sb.toString();
		try {
			i = run.update(conn, sql, values);			
			return i == 1 ? zb : null;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}finally {
			try{
				zb.clearUpdateColumn();
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return null;
			}
		}
	}
	
	public static Zb update(Zb zb,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return update(zb,conn,tableName);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static int[] updateBatch(List<Zb> zbs){
		Connection conn = SK_Config.getConnection();
		return updateBatch(zbs,conn);
	}
	
	public static int[] updateBatch(List<Zb> zbs,Connection conn){
		return updateBatch(zbs,conn,Zb.TABLENAME);
	}
	
	public static int[] updateBatch(List<Zb> zbs,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return updateBatch(zbs,conn);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static int[] updateBatch(List<Zb> zbs,String tableName){
		Connection conn = SK_Config.getConnection();
		return updateBatch(zbs,conn,tableName);
	}
	
	public static int[] updateBatch(List<Zb> zbs,Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		String sql = "UPDATE " +tableName+ " SET id = ?,tempid = ?,攻击人id = ?,目标人id = ?,目标用户名称 = ?,创建时间 = ?,是否可反击 = ?,json = ?,星数 = ?,是否结算 = ?,金币 = ?,水 = ?,开始战斗时间 = ? WHERE id = ?";
		try {
			int columnSize = 13;
			int size = zbs.size();
			Object[][] params = new Object[size][columnSize + 1];
			for (int i = 0; i < size; i++) {
				params[i][0] =zbs.get(i).getId();
				params[i][1] =zbs.get(i).getTempid();
				params[i][2] =zbs.get(i).getGjrid();
				params[i][3] =zbs.get(i).getMbrid();
				params[i][4] =zbs.get(i).getMbyhmc();
				params[i][5] =zbs.get(i).getCjsj();
				params[i][6] =zbs.get(i).getSfkfj();
				params[i][7] =zbs.get(i).getJson();
				params[i][8] =zbs.get(i).getXs();
				params[i][9] =zbs.get(i).getSfjs();
				params[i][10] =zbs.get(i).getJb();
				params[i][11] =zbs.get(i).getS();
				params[i][12] =zbs.get(i).getKszdsj();
				params[i][columnSize] =zbs.get(i).getId();
			}
			int[] is = run.batch(conn,sql,params);
			return is.length > 1 ? is : new int[]{};
		} catch (Exception e) {
			e.printStackTrace();
			return new int[]{};
		} finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return null;
			}
		}
	}
	
	public static int[] updateBatch(List<Zb> zbs,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return updateBatch(zbs,conn,tableName);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}		
	}
	
	public static boolean delete(Zb zb){
		Connection conn = SK_Config.getConnection();
		return delete(zb,conn);
	}
	
	public static boolean delete(Zb zb,Connection conn){
		return delete(zb,conn,Zb.TABLENAME);
	}
	
	public static boolean delete(Zb zb,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return delete(zb,conn);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
	
	public static boolean delete(Zb zb,String tableName){
		Connection conn = SK_Config.getConnection();
		return delete(zb,conn,tableName);
	}
	
	public static boolean delete(Zb zb,Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		String sql = "DELETE FROM " + tableName + " WHERE id = ?";
		try {
			int i = run.update(conn,sql, zb.getId());
			return i > 0 ? true : false;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return false;
			}
		}
	}
	
	public static boolean delete(Zb zb,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return delete(zb,conn,tableName);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
	
	
	public static boolean deleteBatch(List<Zb> zbs){
		Connection conn = SK_Config.getConnection();
		return deleteBatch(zbs,conn);
	}
	
	public static boolean deleteBatch(List<Zb> zbs,Connection conn){
		return deleteBatch(zbs,conn,Zb.TABLENAME);
	}
	
	public static boolean deleteBatch(List<Zb> zbs,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return deleteBatch(zbs,conn);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
	
	public static boolean deleteBatch(List<Zb> zbs,String tableName){
		Connection conn = SK_Config.getConnection();
		return deleteBatch(zbs,conn,tableName);
	}
	
	public static boolean deleteBatch(List<Zb> zbs,Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		String sql = "DELETE FROM " + tableName + " WHERE id = ?";
		try {
			int size = zbs.size();
			Object[][] params = new Object[size][1];
			for (int i = 0; i < size; i++) {
				params[i][0] = zbs.get(i).getId();
			}
			int[] is = run.batch(conn,sql,params);
			return is.length > 0;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return false;
			}
		}
	}
	
	public static boolean deleteBatch(List<Zb> zbs,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return deleteBatch(zbs,conn,tableName);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}

	/**
	 * 根据( id ) 查询
	 */
	public static Zb getById(int id){
		Connection conn = SK_Config.getConnection();
		return getById(id, conn);
	}
	
	public static Zb getById(int id,String tableName){
		Connection conn = SK_Config.getConnection();
		return getById(id, conn,tableName);
	}
	
	/**
	 * 根据( tempid  攻击人id ) 查询
	 */
	public static Zb getByTempidGjrid(int tempid, int gjrid){
		Connection conn = SK_Config.getConnection();
		return getByTempidGjrid(tempid, gjrid, conn);
	}
	
	public static Zb getByTempidGjrid(int tempid, int gjrid,String tableName){
		Connection conn = SK_Config.getConnection();
		return getByTempidGjrid(tempid, gjrid, conn,tableName);
	}
	
	/**
	 * 根据( 攻击人id ) 查询
	 */
	public static List<Zb> getByGjrid(int gjrid){
		Connection conn = SK_Config.getConnection();
		return getByGjrid(gjrid, conn);
	}
	
	public static List<Zb> getByGjrid(int gjrid,String tableName){
		Connection conn = SK_Config.getConnection();
		return getByGjrid(gjrid, conn,tableName);
	}
	
	public static List<Zb> getByPageGjrid(int gjrid,int page,int pageCount){
		Connection conn = SK_Config.getConnection();
		return getByPageGjrid(gjrid, conn,page,pageCount);
	}
	
	public static List<Zb> getByPageGjrid(int gjrid,String tableName,int page,int pageCount){
		Connection conn = SK_Config.getConnection();
		return getByPageGjrid(gjrid, conn,tableName,page,pageCount);
	}
	/**
	 * 根据( 目标人id ) 查询
	 */
	public static List<Zb> getByMbrid(int mbrid){
		Connection conn = SK_Config.getConnection();
		return getByMbrid(mbrid, conn);
	}
	
	public static List<Zb> getByMbrid(int mbrid,String tableName){
		Connection conn = SK_Config.getConnection();
		return getByMbrid(mbrid, conn,tableName);
	}
	
	public static List<Zb> getByPageMbrid(int mbrid,int page,int pageCount){
		Connection conn = SK_Config.getConnection();
		return getByPageMbrid(mbrid, conn,page,pageCount);
	}
	
	public static List<Zb> getByPageMbrid(int mbrid,String tableName,int page,int pageCount){
		Connection conn = SK_Config.getConnection();
		return getByPageMbrid(mbrid, conn,tableName,page,pageCount);
	}
	
	//Connection
	/**
	 * 根据( id ) 查询
	 */
	public static Zb getById(int id,Connection conn){
		return getById(id,conn,Zb.TABLENAME);
	}
	
	public static Zb getById(int id,Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		String sql = "SELECT id,tempid,攻击人id,目标人id,目标用户名称,创建时间,是否可反击,json,星数,是否结算,金币,水,开始战斗时间 FROM " + tableName + " WHERE " + "id = ?";
		Zb zb = null; 
		try {
			Map<String, Object> map = run.query(conn,sql, new MapHandler(), id);
			zb = Zb.createForColumnNameMap(map);
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return null;
			}
		}
		return zb;
	}
	
	/**
	 * 根据( tempid  攻击人id ) 查询
	 */
	public static Zb getByTempidGjrid(int tempid, int gjrid,Connection conn){
		return getByTempidGjrid(tempid, gjrid,conn,Zb.TABLENAME);
	}
	
	public static Zb getByTempidGjrid(int tempid, int gjrid,Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		String sql = "SELECT id,tempid,攻击人id,目标人id,目标用户名称,创建时间,是否可反击,json,星数,是否结算,金币,水,开始战斗时间 FROM " + tableName + " WHERE " + "tempid = ? AND gjrid = ?";
		Zb zb = null; 
		try {
			Map<String, Object> map = run.query(conn,sql, new MapHandler(), tempid, gjrid);
			zb = Zb.createForColumnNameMap(map);
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return null;
			}
		}
		return zb;
	}
	
	/**
	 * 根据( 攻击人id ) 查询
	 */
	public static List<Zb> getByGjrid(int gjrid,Connection conn){
		return getByGjrid(gjrid,conn,Zb.TABLENAME);
	}
	
	public static List<Zb> getByGjrid(int gjrid,Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		String sql = "SELECT id,tempid,攻击人id,目标人id,目标用户名称,创建时间,是否可反击,json,星数,是否结算,金币,水,开始战斗时间 FROM " + tableName + " WHERE " + "gjrid = ?";
		List<Zb> zbs = null; 
		try {
			List<Map<String,Object>> list = run.query(conn, sql, new MapListHandler(), gjrid);
			zbs = Zb.createForColumnNameList(list);
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return null;
			}
		}
		return zbs;
	}
	
	//-----------------------------------page-----------------------------------
	public static List<Zb> getByPageGjrid(int gjrid,Connection conn,int page,int pageCount){
		return getByPageGjrid(gjrid,conn,Zb.TABLENAME,page,pageCount);
	}
	
	public static List<Zb> getByPageGjrid(int gjrid,Connection conn,String tableName,int page,int pageCount){
		QueryRunner run = new QueryRunner();
		page = ((page-1) * pageCount);
		String sql = "SELECT id,tempid,攻击人id,目标人id,目标用户名称,创建时间,是否可反击,json,星数,是否结算,金币,水,开始战斗时间 FROM " + tableName + " WHERE " + "gjrid = ? LIMIT " + page + " , " +pageCount;
		List<Zb> zbs = null; 
		try {
			List<Map<String,Object>> list = run.query(conn, sql, new MapListHandler(), gjrid);
			zbs = Zb.createForColumnNameList(list);
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return null;
			}
		}
		return zbs;
	}
	/**
	 * 根据( 目标人id ) 查询
	 */
	public static List<Zb> getByMbrid(int mbrid,Connection conn){
		return getByMbrid(mbrid,conn,Zb.TABLENAME);
	}
	
	public static List<Zb> getByMbrid(int mbrid,Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		String sql = "SELECT id,tempid,攻击人id,目标人id,目标用户名称,创建时间,是否可反击,json,星数,是否结算,金币,水,开始战斗时间 FROM " + tableName + " WHERE " + "mbrid = ?";
		List<Zb> zbs = null; 
		try {
			List<Map<String,Object>> list = run.query(conn, sql, new MapListHandler(), mbrid);
			zbs = Zb.createForColumnNameList(list);
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return null;
			}
		}
		return zbs;
	}
	
	//-----------------------------------page-----------------------------------
	public static List<Zb> getByPageMbrid(int mbrid,Connection conn,int page,int pageCount){
		return getByPageMbrid(mbrid,conn,Zb.TABLENAME,page,pageCount);
	}
	
	public static List<Zb> getByPageMbrid(int mbrid,Connection conn,String tableName,int page,int pageCount){
		QueryRunner run = new QueryRunner();
		page = ((page-1) * pageCount);
		String sql = "SELECT id,tempid,攻击人id,目标人id,目标用户名称,创建时间,是否可反击,json,星数,是否结算,金币,水,开始战斗时间 FROM " + tableName + " WHERE " + "mbrid = ? LIMIT " + page + " , " +pageCount;
		List<Zb> zbs = null; 
		try {
			List<Map<String,Object>> list = run.query(conn, sql, new MapListHandler(), mbrid);
			zbs = Zb.createForColumnNameList(list);
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return null;
			}
		}
		return zbs;
	}
	
	//DataSource
	/**
	 * 根据( id ) 查询
	 */
	public static Zb getById(int id,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return getById(id, conn);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static Zb getById(int id,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return getById(id, conn);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	/**
	 * 根据( tempid  攻击人id ) 查询
	 */
	public static Zb getByTempidGjrid(int tempid, int gjrid,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return getByTempidGjrid(tempid, gjrid, conn);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static Zb getByTempidGjrid(int tempid, int gjrid,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return getByTempidGjrid(tempid, gjrid, conn);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	/**
	 * 根据( 攻击人id ) 查询
	 */
	public static List<Zb> getByGjrid(int gjrid,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return getByGjrid(gjrid, conn);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static List<Zb> getByGjrid(int gjrid,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return getByGjrid(gjrid, conn);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	//-----------------------------------page-----------------------------------
	public static List<Zb> getByPageGjrid(int gjrid,DataSource ds,int page,int pageCount){
		try {
			Connection conn = ds.getConnection();
			return getByPageGjrid(gjrid, conn,page,pageCount);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static List<Zb> getByPageGjrid(int gjrid,DataSource ds,String tableName,int page,int pageCount){
		try {
			Connection conn = ds.getConnection();
			return getByPageGjrid(gjrid, conn,page,pageCount);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	/**
	 * 根据( 目标人id ) 查询
	 */
	public static List<Zb> getByMbrid(int mbrid,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return getByMbrid(mbrid, conn);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static List<Zb> getByMbrid(int mbrid,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return getByMbrid(mbrid, conn);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	//-----------------------------------page-----------------------------------
	public static List<Zb> getByPageMbrid(int mbrid,DataSource ds,int page,int pageCount){
		try {
			Connection conn = ds.getConnection();
			return getByPageMbrid(mbrid, conn,page,pageCount);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static List<Zb> getByPageMbrid(int mbrid,DataSource ds,String tableName,int page,int pageCount){
		try {
			Connection conn = ds.getConnection();
			return getByPageMbrid(mbrid, conn,page,pageCount);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	
	public static List<Zb> getAll(){
		Connection conn = SK_Config.getConnection();
		return getAll(conn);
	}
	
	public static List<Zb> getAll(Connection conn){
		return getAll(conn,Zb.TABLENAME);
	}
	
	public static List<Zb> getAll(DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return getAll(conn);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static List<Zb> getAll(String tableName){
		Connection conn = SK_Config.getConnection();
		return getAll(conn,tableName);
	}
	
	public static List<Zb> getAll(Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		String sql = "SELECT id,tempid,攻击人id,目标人id,目标用户名称,创建时间,是否可反击,json,星数,是否结算,金币,水,开始战斗时间 FROM " + tableName;
		List<Zb> zbs = null; 
		try {
			List<Map<String,Object>> list = run.query(conn, sql, new MapListHandler());
			zbs = Zb.createForColumnNameList(list);
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return null;
			}
		}
		return zbs;
	}
	
	public static List<Zb> getAll(DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return getAll(conn,tableName);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}		
	}
	
	public static List<Zb> getAllPage(int page,int pageCount){
		Connection conn = SK_Config.getConnection();
		return getAllPage(conn,page,pageCount);
	}
	
	public static List<Zb> getAllPage(Connection conn,int page,int pageCount){
		return getAllPage(conn,Zb.TABLENAME,page,pageCount);
	}
	
	public static List<Zb> getAllPage(DataSource ds,int page,int pageCount){
		try {
			Connection conn = ds.getConnection();
			return getAllPage(conn,page,pageCount);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static List<Zb> getAllPage(String tableName,int page,int pageCount){
		Connection conn = SK_Config.getConnection();
		return getAllPage(conn,tableName,page,pageCount);
	}
	
	public static List<Zb> getAllPage(Connection conn,String tableName,int page,int pageCount){
		QueryRunner run = new QueryRunner();
		page = ((page-1) * pageCount);
		String sql = "SELECT id,tempid,攻击人id,目标人id,目标用户名称,创建时间,是否可反击,json,星数,是否结算,金币,水,开始战斗时间 FROM " + tableName + " LIMIT " + page + " , " +pageCount;
		List<Zb> zbs = null; 
		try {
			List<Map<String,Object>> list = run.query(conn, sql, new MapListHandler());
			zbs = Zb.createForColumnNameList(list);
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				e1.printStackTrace();
				return null;
			}
		}
		return zbs;
	}
	
	public static List<Zb> getAllPage(DataSource ds,String tableName,int page,int pageCount){
		try {
			Connection conn = ds.getConnection();
			return getAllPage(conn,tableName,page,pageCount);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}		
	}
}